<?php

namespace app\admin\controller\air;

use app\common\controller\Backend;
use app\admin\model\air\Setting as SettingModel;

/**
 * 设置信息
 *
 * @icon fa fa-circle-o
 */
class Setting extends Backend
{

    /**
     * Setting模型对象
     * @var \app\admin\model\air\Setting
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\air\Setting;

    }



    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */

    public function index($ids = null)
    {
        $allSettings = SettingModel::getSettings(); 
        $introPic1 = SettingModel::getSingleSetting('intro_pic1', $allSettings);
        $introPic2 = SettingModel::getSingleSetting('intro_pic2', $allSettings);
        $defaultPic = SettingModel::getSingleSetting('default_pic', $allSettings);
        $indexSalePic = SettingModel::getSingleSetting('index_sale_pic', $allSettings);
        $mpPic = SettingModel::getSingleSetting('mp_pic', $allSettings);
        $customPic = SettingModel::getSingleSetting('custom_pic', $allSettings);
        $customPhone = SettingModel::getSingleSetting('custom_phone', $allSettings);


        $planeQuotePic = SettingModel::getSingleSetting('plane_quote_pic', $allSettings);
        $charterQuotePic = SettingModel::getSingleSetting('charter_quote_pic', $allSettings);
        $joinQuotePic = SettingModel::getSingleSetting('join_quote_pic', $allSettings);
        $customQuotePic = SettingModel::getSingleSetting('custom_quote_pic', $allSettings);
        $softAgreements = SettingModel::getSingleSetting('soft_agreements', $allSettings);

        $switchSale = SettingModel::getSingleSetting('switch_sale', $allSettings);
        $switchCharter = SettingModel::getSingleSetting('switch_charter', $allSettings);
        $switchCustom = SettingModel::getSingleSetting('switch_custom', $allSettings);
        $sharePic = SettingModel::getSingleSetting('share_pic', $allSettings);

        if ($this->request->isPost()) {
            SettingModel::where('name', 'intro_pic1')
              ->update(['value' => $this->request->post('intro_pic1')]);

            SettingModel::where('name', 'intro_pic2')
              ->update(['value' => $this->request->post('intro_pic2')]);

            SettingModel::where('name', 'default_pic')
              ->update(['value' => $this->request->post('default_pic')]);

            SettingModel::where('name', 'index_sale_pic')
              ->update(['value' => $this->request->post('index_sale_pic')]);

            SettingModel::where('name', 'mp_pic')
              ->update(['value' => $this->request->post('mp_pic')]);

            SettingModel::where('name', 'custom_pic')
              ->update(['value' => $this->request->post('custom_pic')]);

            SettingModel::where('name', 'custom_phone')
              ->update(['value' => $this->request->post('custom_phone')]);

            SettingModel::where('name', 'plane_quote_pic')
              ->update(['value' => $this->request->post('plane_quote_pic')]);

            SettingModel::where('name', 'charter_quote_pic')
              ->update(['value' => $this->request->post('charter_quote_pic')]);

            SettingModel::where('name', 'join_quote_pic')
              ->update(['value' => $this->request->post('join_quote_pic')]);

            SettingModel::where('name', 'custom_quote_pic')
              ->update(['value' => $this->request->post('custom_quote_pic')]);
            SettingModel::where('name', 'soft_agreements')
              ->update(['value' => $this->request->post('soft_agreements')]);

            SettingModel::where('name', 'switch_sale')
              ->update(['value' => $this->request->post('switch_sale')]);
            SettingModel::where('name', 'switch_custom')
              ->update(['value' => $this->request->post('switch_custom')]);
            SettingModel::where('name', 'switch_charter')
              ->update(['value' => $this->request->post('switch_charter')]);
            SettingModel::where('name', 'share_pic')
              ->update(['value' => $this->request->post('share_pic')]);

            $this->success("保存成功");

        }
        $this->view->assign('intro_pic1', $introPic1);
        $this->view->assign('intro_pic2', $introPic2);
        $this->view->assign('default_pic', $defaultPic);
        $this->view->assign('index_sale_pic', $indexSalePic);
        $this->view->assign('mp_pic', $mpPic);
        $this->view->assign('custom_phone', $customPhone);
        $this->view->assign('custom_pic', $customPic);

        $this->view->assign('plane_quote_pic', $planeQuotePic);
        $this->view->assign('charter_quote_pic', $charterQuotePic);
        $this->view->assign('join_quote_pic', $joinQuotePic);
        $this->view->assign('custom_quote_pic', $customQuotePic);
        $this->view->assign('soft_agreements', $softAgreements);
        $this->view->assign('switch_sale', $switchSale);
        $this->view->assign('switch_custom', $switchCustom);
        $this->view->assign('switch_charter', $switchCharter);
        $this->view->assign('share_pic', $sharePic);
        return $this->view->fetch();
    }

}
